package com.zhc.dejingapi.service.upload.impl;

import com.zhc.dejingapi.pojo.qingflow.QingflowApiInfo;
import com.zhc.dejingapi.service.upload.IQingFlowDataDownloadService;
import com.zhc.dejingapi.utils.PubInfoUtils;
import com.zhc.dejingapi.utils.common.DateTimeUtils;
import com.zhc.dejingapi.utils.downqing.QingDownDataSelFieldUtils;
import com.zhc.dejingapi.utils.downqing.QingDownDataUtils;
import com.zhc.dejingapi.utils.downqing.QingDownLastDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
public class QingFlowDataDownloadServiceImpl implements IQingFlowDataDownloadService {

    @Autowired
    QingflowApiInfo qqingflowApiInfo;


    @Qualifier("mySqlJdbcTemplate")
    private final JdbcTemplate mySqlJdbcTemplate;

    private final RedisTemplate<String,Object> redisTemplate;


    public QingFlowDataDownloadServiceImpl(@Qualifier("mySqlJdbcTemplate")JdbcTemplate mySqlJdbcTemplate1,
                                           @Qualifier("redisTemplateWin")RedisTemplate<String, Object> redisTemplate1) {
        this.redisTemplate = redisTemplate1;
        this.mySqlJdbcTemplate = mySqlJdbcTemplate1;
    }

    @Override
    public boolean downPRoutingData() {


        String strAppkey="7llbdgmg1c01";
        //qingflowApiInfo qqingflowApiInfo,String strAppKey,long  queId, String minDate,String maxDate

        QingDownDataUtils qingDownDataUtils=new QingDownDataUtils(strAppkey,mySqlJdbcTemplate,qqingflowApiInfo);

        String strQingFieldTitle="更新时间";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
        String strNowBatch=sdf.format(new Date());

        final String strSql="insert into qing_downdatabatch(appKey,downBatchId,downDate,isValid,mainTableName) values(?,?,?,?,?);";
        List<Object> listPara=new ArrayList<>();
        listPara.add(strAppkey);
        listPara.add(strNowBatch);
        listPara.add(new Date());
        listPara.add(0);
        listPara.add(qingDownDataUtils.getMainDBModel().getMainTableName());

        try{
            KeyHolder keyHolder = new GeneratedKeyHolder();
            mySqlJdbcTemplate.update(new PreparedStatementCreator() {
                @Override
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(strSql,
                            Statement.RETURN_GENERATED_KEYS);
                    ps.setObject(1,listPara.get(0));
                    ps.setObject(2,listPara.get(1));
                    ps.setObject(3,listPara.get(2));
                    ps.setObject(4,listPara.get(3));
                    ps.setObject(5,listPara.get(4));
                    return ps;

                }
            },keyHolder);
            long  lValue=keyHolder.getKey().longValue();


            //mySqlJdbcTemplate.update(strSql,listPara.toArray());
          boolean bSuccess=  qingDownDataUtils.getAppDownData(strNowBatch,strQingFieldTitle,"2024-07-26 00:00:00","2090-07-26 00:00:00");
          if (bSuccess){
              //只保留最近两次的结果
          }
        }
        catch (Exception e){
            e.printStackTrace();
            log.error("下载数据失败");
        }

        return false;
    }

    @Override
    public boolean downProductExtenData() {


        String strAppkey="7uk2jrrc1o01";
        //qingflowApiInfo qqingflowApiInfo,String strAppKey,long  queId, String minDate,String maxDate

        QingDownDataUtils qingDownDataUtils=new QingDownDataUtils(strAppkey,mySqlJdbcTemplate,qqingflowApiInfo);

        String strQingFieldTitle="更新时间";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
        String strNowBatch=sdf.format(new Date());

        final String strSql="insert into qing_downdatabatch(appKey,downBatchId,downDate,isValid,mainTableName) values(?,?,?,?,?);";
        List<Object> listPara=new ArrayList<>();
        listPara.add(strAppkey);
        listPara.add(strNowBatch);
        listPara.add(new Date());
        listPara.add(0);
        listPara.add(qingDownDataUtils.getMainDBModel().getMainTableName());
        try{
            KeyHolder keyHolder = new GeneratedKeyHolder();
            mySqlJdbcTemplate.update(new PreparedStatementCreator() {
                @Override
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(strSql,
                            Statement.RETURN_GENERATED_KEYS);
                    ps.setObject(1,listPara.get(0));
                    ps.setObject(2,listPara.get(1));
                    ps.setObject(3,listPara.get(2));
                    ps.setObject(4,listPara.get(3));
                    ps.setObject(5,listPara.get(4));
                    return ps;

                }
            },keyHolder);
            long  lValue=keyHolder.getKey().longValue();

           String strStartDate="2024-08-01 00:00:00";
           String strEndDate="2090-12-31 12:59:59";

            //mySqlJdbcTemplate.update(strSql,listPara.toArray());
            boolean bSuccess=  qingDownDataUtils.getAppDownData(strNowBatch,strQingFieldTitle,strStartDate,strEndDate);
            if (bSuccess){
                //只保留最近两次的结果
            }
        }
        catch (Exception e){
            e.printStackTrace();
            log.error("下载数据失败");
            return  false;
        }

        return true;
    }

    @Override
    public boolean downMoOrderData() {

        String appKey="7m7ph33k1c01";
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

        PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);

        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }

        return true;
    }

    @Override
    public boolean downProductPicSop() {


        String strAppkey="7llji6p41c01";//产品档案
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{strAppkey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{strAppkey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{strAppkey},Date.class);

        }
        Date dNowDate=new Date();

        QingDownDataSelFieldUtils qingDownLastDataUtils=new QingDownDataSelFieldUtils(strAppkey,mySqlJdbcTemplate,qqingflowApiInfo);

        if(dLastDate==null){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        if(qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate)){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,strAppkey});
        }



        return true;
    }

    //下载部门
    @Override
    public Boolean downDepartment() {


        //61	7lsjms5s1c01	部门


        String appKey="7lsjms5s1c01";
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-07-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();



        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);

        String strminDate=sdf.format(dLastDate);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }



        return true;
    }
    //下载人员

    @Override
    public Boolean downPerson() {

        //60	7lskdfj01c01	用户

        String appKey="7lskdfj01c01";
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-07-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();


        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }
        return true;
    }

    @Override
    public Boolean downWorkShift() {
        //76	7ll5kbu81c02	班次管理	0	1	0

        String appKey="7ll5kbu81c02";
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-07-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }
        return true;
    }


    //下载注塑工单
    @Override
    public Boolean downInjectTask() {

        String appKey="7nhiubrg1k02";//注塑任务单

        //7	7po3uj601o01	后道任务单
        //12	7o7pqmug1k02	水煮任务单
        //30	7nhiubrg1k02	注塑任务单
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);
        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();
        //PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);

        Map<String,String> mapDefaultFieldValue=new HashMap<>();
        mapDefaultFieldValue.put("appKey",appKey);
        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo,mapDefaultFieldValue);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }

        return true;
    }

    //下载水煮工单
    @Override
    public Boolean downWaterBoiledTask() {

        String appKey="7o7pqmug1k02";
        //7	7po3uj601o01	后道任务单
        //12	7o7pqmug1k02	水煮任务单
        //30	7nhiubrg1k02	注塑任务单
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

       // PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);
        Map<String,String> mapDefaultFieldValue=new HashMap<>();
        mapDefaultFieldValue.put("appKey",appKey);
        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo,mapDefaultFieldValue);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }


        return true;
    }

    //下载压管工单
    @Override
    public Boolean downPressTubeTask() {

        String appKey="7po3uj601o01";
        //7	7po3uj601o01	后道任务单
        //12	7o7pqmug1k02	水煮任务单
        //30	7nhiubrg1k02	注塑任务单
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

        //PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);
        Map<String,String> mapDefaultFieldValue=new HashMap<>();
        mapDefaultFieldValue.put("appKey",appKey);
        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo,mapDefaultFieldValue);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }


        return true;
    }

    @Override
    public Boolean downWaterBoiledTaskStartData() {

        String appKey="7v93shmc1o01";
        //7v93shmc1o01	水煮启动报工
        //7	7po3uj601o01	后道任务单
        //12	7o7pqmug1k02	水煮任务单
        //30	7nhiubrg1k02	注塑任务单
        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

        //PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);
        Map<String,String> mapDefaultFieldValue=new HashMap<>();

        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }

        return true;
    }

    @Override
    public Boolean downEquipment() {

        String appKey="7llr2okg1c01";
        //65	7llr2okg1c01	设备档案

        String strSql="select count(*) from qing_downlstdaterecord where appKey=?";
        int iHaveCount=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Integer.class);
        Date dLastDate=null;

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(iHaveCount<1){
            strSql="insert  into qing_downlstdaterecord(appKey,lastUpdDate) values(?,?)";
            mySqlJdbcTemplate.update(strSql,new Object[]{appKey,null});
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }

        }
        else{
            strSql="select lastUpdDate from qing_downlstdaterecord where appKey=?";
            dLastDate=mySqlJdbcTemplate.queryForObject(strSql,new Object[]{appKey},Date.class);

        }
        if(dLastDate==null ){
            try{
                dLastDate=sdf.parse("2024-08-01 00:00:00");
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
        Date dNowDate=new Date();

        //PubInfoUtils.LoadMakeList(mySqlJdbcTemplate);
        Map<String,String> mapDefaultFieldValue=new HashMap<>();

        QingDownLastDataUtils qingDownLastDataUtils=new QingDownLastDataUtils(appKey,mySqlJdbcTemplate,qqingflowApiInfo);
        dLastDate= DateTimeUtils.AddDay(dLastDate,-1);//减少一天
        String strminDate=sdf.format(dLastDate);
        String strmaxDate="2090-12-31 23:59:59";
        String strQingFieldTitle="更新时间";
        Boolean bSuccess=qingDownLastDataUtils.getAppDownData(strQingFieldTitle,strminDate,strmaxDate);
        if(bSuccess){
            strSql="update qing_downlstdaterecord set lastUpdDate=? where appKey=?";
            mySqlJdbcTemplate.update(strSql,new Object[]{dNowDate,appKey});
        }


        return true;
    }


}
